% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/aggregate.R
\name{by_split}
\alias{by_split}
\title{Apply a function per group and combine results}
\usage{
by_split(x, factors, fn, mc.cores = 1, ...)
}
\arguments{
\item{x}{An R object, either \code{data.frame} or \code{matrix}}

\item{factors}{Factor or list of factors passed to
\code{\link{split}} and \code{\link{unsplit}}}

\item{fn}{Function to apply to each group}

\item{mc.cores}{Number of cores to use as parallel jobs.}

\item{...}{Additional arguments passed to
\code{\link[parallel]{mclapply}}}
}
\value{
Object of same class as \code{x}.
}
\description{
Simple wrapper around the conventional split-lapply-unsplit pattern
that, unlike \code{\link{by}}, returns a combined object.
}
\section{Warning}{
 \code{by_split} assumes that the subsets returned
    by the function \code{f} are of the same class as the
    original object.
}

\examples{
df <- data.frame(x = c(1, 1, 2, 2), y = c(1, NA, NA, 4))
by_split(df, df$x, locf)

}
